home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / utilities / printer / post-1.6src.lzh / postlib.a < prev    next >
Text File  |  1991-04-19  |  18KB  |  571 lines

  1. ;***************************************************************************
  2. ;
  3. ; PostScript interpreter file "postlib.a" - library structure (Amiga)
  4. ; (C) Adrian Aylward 1989, 1991
  5. ;
  6. ; This file contains the library structure to which the interpreter objects
  7. ; are linked.  It is Lattice specific.  Whenever a new instance of a
  8. ; PostScript is activated it creates a new data segment for it, in like
  9. ; manner to the cres.o startup.  The library code itself is based on the
  10. ; skeleton in the RKM.
  11. ;
  12. ;***************************************************************************
  13.  
  14.         include "exec/types.i"
  15.         include "exec/nodes.i"
  16.         include "exec/lists.i"
  17.         include "exec/libraries.i"
  18.         include "exec/alerts.i"
  19.         include "exec/initializers.i"
  20.         include "exec/resident.i"
  21.         include "exec/memory.i"
  22.         include "exec/execbase.i"
  23.         include "exec/funcdef.i"
  24.         include "exec/exec_lib.i"
  25.         include "libraries/dosextens.i"
  26.  
  27. ; Linker symbols for the data segment
  28.  
  29.         xref    LinkerDB        ; Base of data segment
  30.         xref    RESLEN          ; Length of data+bss segment
  31.         xref    RESBASE         ; Base offset of data+bss segment
  32.         xref    NEWDATAL        ; Number of longs in data
  33.  
  34. ; Version numbers
  35.  
  36. VERSION EQU     16      ; Version nuber
  37. REV     EQU     0       ; Revision number
  38.  
  39. ; Library base
  40.  
  41.         STRUCTURE pslib,LIB_SIZE
  42.         ULONG   pl_EXECBASE
  43.         ULONG   pl_DOSBASE
  44.         ULONG   pl_SEGLIST
  45.         UBYTE   pl_FLAGS
  46.         UBYTE   pl_pad
  47.         LABEL   pl_SIZE
  48.  
  49. ;***************************************************************************
  50. ;
  51. ; The text segment (must be the first hunk).
  52. ;
  53. ;***************************************************************************
  54.  
  55.         csect   text,0
  56.  
  57.     xref    MemCleanup          ; Free all allocated memory
  58.  
  59.     xref    initialise                ; Initialise the interpreter
  60.         xref    terminate                 ; Terminate the interpreter
  61.         xref    intstring                 ; Interpret a string or file
  62.         xref    signalint                 ; Signal an interrupt
  63.         xref    signalfpe                 ; Signal a floating point error
  64.         xref    error                     ; Error
  65.         xref    vmalloc                   ; Allocate VM space
  66.         xref    vmxptr                    ; Convert VM reference to pointer
  67.         xref    setdevice                 ; Change device page
  68.         xref    errstr                    ; Return error name string
  69.  
  70.         xdef    callextfunc               ; Call external function
  71.         xdef    flushpage                 ; Flush the page to the screen
  72.         xdef    copypage                  ; Copy the page to the output
  73.  
  74. ;***************************************************************************
  75. ;
  76. ; The standard library header
  77. ;
  78. ;***************************************************************************
  79.  
  80. ; Return zero, in case someone tries to run us as a program
  81.  
  82.         moveq   #0,d0
  83.         rts
  84.  
  85. ; Romtag structure
  86.  
  87. romtag: dc.w    RTC_MATCHWORD             ; UWORD RT_MATCHWORD
  88.         dc.l    romtag                    ; APTR  RT_MATCHTAG
  89.         dc.l    romend                    ; APTR  RT_ENDSKIP
  90.         dc.b    RTF_AUTOINIT              ; UBYTE RT_FLAGS
  91.         dc.b    VERSION                   ; UBYTE RT_VERSION
  92.         dc.b    NT_LIBRARY                ; UBYTE RT_TYPE
  93.         dc.b    0                         ; UBYTE RT_PRI
  94.         dc.l    name                      ; APTR  RT_NAME
  95.         dc.l    idstring                  ; APTR  RT_IDSTRING
  96.         dc.l    inittab                   ; APTR  RT_INIT
  97. romend:
  98.  
  99. ; Name strings
  100.  
  101. name:   dc.b    'post.library',0
  102.  
  103. idstring:
  104.         dc.b    'PostLib 1.6 (19 Apr 1991)',13,10,0
  105.  
  106. dosname:
  107.         dc.b    'dos.library',0
  108.  
  109.         ds.w    0
  110.  
  111. ; Initialisation table
  112.  
  113. inittab:
  114.         dc.l    pl_SIZE                   ; Data space size
  115.         dc.l    functab                   ; Function initialisers
  116.         dc.l    datatab                   ; Data initialisers
  117.         dc.l    init                      ; Routine to run
  118.  
  119. functab:
  120.         dc.l    open                      ; Standard entries
  121.         dc.l    close
  122.         dc.l    expunge
  123.         dc.l    null
  124.         dc.l    pscreateact               ; Create an activation
  125.         dc.l    psdeleteact               ; Delete an activation
  126.         dc.l    psintstring               ; Interpret a string or file
  127.         dc.l    pssignalint               ; Signal interrupt
  128.         dc.l    pssignalfpe               ; Signal floating point error
  129.         dc.l    pserror                   ; Error
  130.         dc.l    psallocvm                 ; Allocate VM space
  131.         dc.l    psvreftoptr               ; Convert VM reference to pointer
  132.         dc.l    pssetdevice               ; Set new device page
  133.         dc.l    pserrstr                  ; Return error name string
  134.         dc.l    -1
  135.  
  136. datatab:
  137.         INITBYTE        LN_TYPE,NT_LIBRARY
  138.         INITLONG        LN_NAME,name
  139.         INITBYTE        LIB_FLAGS,LIBF_SUMUSED+LIBF_CHANGED
  140.         INITWORD        LIB_VERSION,VERSION
  141.         INITWORD        LIB_REVISION,REV
  142.         INITLONG        LIB_IDSTRING,idstring
  143.         dc.l    0
  144.  
  145. ;***************************************************************************
  146. ;
  147. ; Initialisation and standard library entries
  148. ;
  149. ; Initialisation, open, close, expunge routines
  150. ;
  151. ;***************************************************************************
  152.  
  153. ; Initialisation routine
  154.  
  155. init:   move.l  a5,-(sp)
  156.         move.l  d0,a5                     ; Library base
  157.         move.l  a6,pl_EXECBASE(a5)        ; Exec base
  158.         move.l  a0,pl_SEGLIST(a5)         ; Segment list
  159.     lea     dosname(pc),a1
  160.     moveq   #0,D0
  161.         jsr     _LVOOpenLibrary(a6)       ; Open DOS library
  162.     move.l  d0,pl_DOSBASE(A5)
  163.     bne.s   in1    
  164.  
  165.         ALERT   AG_OpenLib+AO_DOSLib      ; Alert if we can't open DOS
  166.  
  167. in1:    move.l  a5,d0
  168.         move.l  (sp)+,a5
  169.         rts
  170.  
  171. ; Open routine
  172.  
  173. open:   move.l  a0,-(sp)
  174.         move.l  4,a0
  175.         move.w  AttnFlags(a0),d0          ; Special attention flags
  176.         bsr.s   getdb
  177.         sub.l   #RESBASE,a0
  178.         and.w   attnflags(a0),d0          ; Check for FPU (68881/68020 ...)
  179.         cmp.w   attnflags(a0),d0
  180.         move.l  (sp)+,a0
  181.         beq.s   op1
  182.  
  183.         moveq   #0,d0                     ; No FPU if needed, can't open
  184.         rts
  185.  
  186. op1:    addq.w  #1,LIB_OPENCNT(a6)        ; Increment open count
  187.         bclr    #LIBB_DELEXP,pl_FLAGS(a6) ; Clear delayed expunge
  188.         move.l  a6,d0                     ; Return library base
  189.         rts
  190.  
  191. getdb:  lea     LinkerDB,a0               ; Original data segment
  192.         rts
  193.  
  194. ; Close routine
  195.  
  196. close:  moveq   #0,d0
  197.         subq.w  #1,LIB_OPENCNT(a6)        ; Decrement open count
  198.         bne.s   cl1
  199.         btst    #LIBB_DELEXP,pl_FLAGS(a6) ; Check for delayed expunge
  200.         bne.s   expunge                   ; Expunge
  201. cl1:    rts
  202.  
  203. ; Expunge routine
  204.  
  205. expunge:
  206.         movem.l d2/a5/a6,-(sp)
  207.         move.l  a6,a5                     ; Library base
  208.         move.l  pl_EXECBASE(a5),a6        ; ExecBase
  209.         tst.w   LIB_OPENCNT(a5)           ; Still open?
  210.         beq     ex1
  211.  
  212.         bset    #LIBB_DELEXP,pl_FLAGS(a5) ; Flag delayed expunge
  213.         moveq   #0,d0
  214.         bra.s   ex2
  215.  
  216. ex1:    move.l  pl_SEGLIST(a5),d2         ; We will return the segment list
  217.         move.l  a5,a1
  218.         jsr     _LVORemove(a6)            ; Remove from list
  219.         move.l  pl_DOSBASE(a5),a1
  220.         jsr     _LVOCloseLibrary(a6)      ; Close DOS library
  221.         moveq   #0,d0
  222.         move.l  a5,a1
  223.         move.w  LIB_NEGSIZE(a5),d0
  224.         sub.l   d0,a1
  225.         add.w   LIB_POSSIZE(a5),d0
  226.         jsr     _LVOFreeMem(a6)           ; Free the memory
  227.         move.l  d2,d0
  228.  
  229. ex2:    movem.l (sp)+,d2/a5/a6
  230.         rts
  231.  
  232. ; Null routine (reserved)
  233.  
  234. null:   moveq   #0,d0
  235.         rts
  236.  
  237. ;***************************************************************************
  238. ;
  239. ; User defined library entries
  240. ;
  241. ;***************************************************************************
  242. ;
  243. ; Create a PostScript activation
  244. ;
  245. ;         d0:int arec = PScreateact(a1:struct PSparm *parm)
  246. ;
  247. ;***************************************************************************
  248.  
  249. pscreateact:
  250.         movem.l a2-a6,-(sp)
  251.         move.l  a1,a2                     ; parm
  252.         move.l  a6,a5
  253.         move.l  pl_EXECBASE(a6),a6        ; ExecBase
  254.         move.l  #RESLEN,d0                ; Length of data segment
  255.         move.l  #MEMF_CLEAR+MEMF_PUBLIC,d1
  256.         jsr     _LVOAllocMem(a6)          ; Allocate the memory
  257.         tst.l   d0                        ; New data segment
  258.         beq.s   cax                       ; No memory, return zero
  259.         move.l  d0,a3                     ; New data segment
  260.         bsr.w   getdb
  261.         sub.l   #RESBASE,a0
  262.         move.l  #NEWDATAL,d1              ; Number of longs (<64K!)
  263.         bra.s   ca2
  264.  
  265. ca1:    move.l  (a0)+,(a3)+               ; Copy data
  266. ca2:    dbf     d1,ca1
  267.  
  268.         move.l  (a0)+,d1                  ; Number of relocs (<64K!)
  269.         bra.s   ca4
  270.  
  271. ca3:    move.l  (a0)+,a3                  ; Offset to relocate
  272.         add.l   d0,a3                     ; Address to relocate
  273.         add.l   d0,(a3)                   ; Relocate it
  274. ca4:    dbf     d1,ca3
  275.  
  276.         move.l  d0,a4                     ; New data segment
  277.         add.l   #RESBASE,a4
  278.         move.l  pl_EXECBASE(a5),SysBase(a4)
  279.         move.l  pl_DOSBASE(a5),DOSBase(a4)
  280.         move.l  ThisTask(a6),a3           ; Current directory
  281.         move.l  pr_CurrentDir(a3),curdir(a4)
  282.  
  283.         move.l  a2,-(sp)                  ; parm
  284.         jsr     initialise(pc)            ; Call initialisation routine
  285.         addq.l  #4,sp
  286.  
  287.         cmp.l   #-1,d0
  288.         bne.s   da1                       ; Failed to initialise, tidy up
  289.  
  290.         move.l  a4,d0
  291.         sub.l   #RESBASE,a4               ; Return base of new segment
  292.  
  293. cax:    movem.l (sp)+,a2-a6
  294.         rts
  295.  
  296.  
  297. ;***************************************************************************
  298. ;
  299. ; Delete a PostScript activation
  300. ;
  301. ;         PSdeleteact(a0:APTR arec)
  302. ;
  303. ;***************************************************************************
  304.  
  305. psdeleteact:
  306.         movem.l a2-a6,-(sp)
  307.         move.l  a0,a4
  308.         add.l   #RESBASE,a4
  309.  
  310. da1:    move.l  d0,-(sp)                  ; Save result for return
  311.         jsr     terminate(pc)             ; Call termination routine
  312.         jsr     MemCleanup(pc)            ; Cleanup leftover memory
  313.         move.l  #RESLEN,d0                ; Length of data segment
  314.         move.l  SysBase(a4),a6
  315.         move.l  a4,a1
  316.         sub.l   #RESBASE,a1
  317.         jsr     _LVOFreeMem(a6)           ; Free the memory
  318.         move.l  (sp)+,d0                  ; Restore result
  319.         movem.l (sp)+,a2-a6
  320.         rts
  321.  
  322. ;***************************************************************************
  323. ;
  324. ; Interpret a string or file
  325. ;
  326. ;         d0:int errnum = PSintstring(a0:APTR arec, a1:char *string,
  327. ;                                     d0:int length, d1:int flags)
  328. ;
  329. ;***************************************************************************
  330.  
  331. psintstring:
  332.         move.l  a4,-(sp)
  333.         move.l  a0,a4
  334.         add.l   #RESBASE,a4
  335.         move.l  d1,-(sp)                  ; Flags
  336.         move.l  d0,-(sp)                  ; Length
  337.         move.l  a1,-(sp)                  ; String
  338.         jsr     intstring(pc)             ; Call interpreter
  339.         add.w   #12,sp
  340.         move.l  (sp)+,a4
  341.         rts
  342.  
  343. ;***************************************************************************
  344. ;
  345. ; Signal an interrupt
  346. ;
  347. ;         PSsignalint(a0:APTR arec, d0:int flag)
  348. ;
  349. ;***************************************************************************
  350.  
  351. pssignalint:
  352.         move.l  a4,-(sp)
  353.         move.l  a0,a4
  354.         add.l   #RESBASE,a4
  355.         move.l  d0,-(sp)                  ; flag
  356.         jsr     signalint(pc)             ; Signal interupt
  357.         addq.l  #4,sp
  358.         move.l  (sp)+,a4
  359.         rts
  360.  
  361. ;***************************************************************************
  362. ;
  363. ; Signal a floating point error
  364. ;
  365. ;         PSsignalfpe(a0:APTR arec)
  366. ;
  367. ;***************************************************************************
  368.  
  369. pssignalfpe:
  370.         move.l  a4,-(sp)
  371.         move.l  a0,a4
  372.         add.l   #RESBASE,a4
  373.         jsr     signalfpe(pc)             ; Signal floating point error
  374. ;       move.l  (sp)+,a4                  ; No return
  375. ;       rts
  376.  
  377. ;***************************************************************************
  378. ;
  379. ; Error
  380. ;
  381. ;         PSerror(a0:APTR arec, d0:int errnum)
  382. ;
  383. ;***************************************************************************
  384.  
  385. pserror:
  386.         move.l  a4,-(sp)
  387.         move.l  a0,a4
  388.         add.l   #RESBASE,a4
  389.         move.l  d0,-(sp)
  390.         jsr     error(pc)                 ; Call error routine
  391. ;       addq.l  #4,sp                     ; No return
  392. ;       move.l  (sp)+,a4
  393. ;       rts
  394.  
  395. ;***************************************************************************
  396. ;
  397. ; Allocate VM space
  398. ;
  399. ;         d0:unsigned vref = PSallocvm(a0:APTR arec, d0:int size)
  400. ;
  401. ;***************************************************************************
  402.  
  403. psallocvm:
  404.         move.l  a4,-(sp)
  405.         move.l  a0,a4
  406.         add.l   #RESBASE,a4
  407.         move.l  d0,-(sp)
  408.         jsr     vmalloc(pc)               ; Allocae VM space
  409.         addq.l  #4,sp
  410.         move.l  (sp)+,a4
  411.         rts
  412.  
  413. ;***************************************************************************
  414. ;
  415. ; Convert VM reference to pointer
  416. ;
  417. ;         a0:void *vptr = PSvreftoptr(a0:APTR arec, d0:unsigned vref)
  418. ;
  419. ;***************************************************************************
  420.  
  421. psvreftoptr:
  422.         move.l  a4,-(sp)
  423.         move.l  a0,a4
  424.         add.l   #RESBASE,a4
  425.         move.l  d0,-(sp)
  426.         jsr     vmxptr(pc)                ; Convert VM reference to pointer
  427.         addq.l  #4,sp
  428.         move.l  (sp)+,a4
  429.         rts
  430.  
  431. ;***************************************************************************
  432. ;
  433. ; Change device page
  434. ;
  435. ;         PSsetdevice(a0:APTR arec, a1:struct PSdevice *page)
  436. ;
  437. ;***************************************************************************
  438.  
  439. pssetdevice:
  440.         move.l  a4,-(sp)
  441.         move.l  a0,a4
  442.         add.l   #RESBASE,a4
  443.         move.l  a1,-(sp)
  444.         jsr     setdevice(pc)             ; Change device page
  445.         addq.l  #4,sp
  446.         move.l  (sp)+,a4
  447.         rts
  448.  
  449. ;***************************************************************************
  450. ;
  451. ; Return error name string
  452. ;
  453. ;         PSerrstr(a0:APTR arec, d0:int errnum)
  454. ;
  455. ;***************************************************************************
  456.  
  457. pserrstr:
  458.         move.l  a4,-(sp)
  459.         move.l  a0,a4
  460.         add.l   #RESBASE,a4
  461.         move.l  d0,-(sp)
  462.         jsr     errstr(pc)                ; Return error name string
  463.         addq.l  #4,sp
  464.         move.l  (sp)+,a4
  465.         rts
  466.  
  467. ;***************************************************************************
  468. ;
  469. ; Other assembler routines
  470. ;
  471. ;***************************************************************************
  472. ;
  473. ; Call an external function, using a C calling sequence
  474. ;
  475. ;     void callextfunc(APTR func, int *argv, int argc)
  476. ;
  477. ;***************************************************************************
  478.  
  479. callextfunc:
  480.         move.l  4(sp),a0                  ; Function
  481.         move.l  8(sp),a1                  ; Parameters array
  482.         move.l  12(sp),d0                 ; Number of parameters
  483.         move.l  a5,-(sp)                  ; Save the stack pointer
  484.         move.l  sp,a5
  485.         move.l  d0,d1
  486.         lsl.l   #2,d1
  487.         add.l   d1,a1                     ; End of parameters array
  488.         bra.s   cf2
  489.  
  490. cf1:    move.l  -(a1),-(sp)               ; Push object value unto stack
  491. cf2:    dbf     d0,cf1
  492.  
  493.         jsr     (a0)                      ; call the function
  494.         move.l  a5,sp                     ; restore the stack pointer
  495.         move.l  (sp)+,a5
  496.         rts
  497.  
  498. ;***************************************************************************
  499. ;
  500. ; Flush the page to the screen.  Call the flush function if we have one.
  501. ;
  502. ;     void flushpage(int y1, int y2)
  503. ;
  504. ;***************************************************************************
  505.  
  506. flushpage:
  507.         move.l  flushfunc(a4),d0          ; Get the function
  508.         beq.s   fp1
  509.         move.l  d0,-(sp)                  ; Push function
  510.         move.l  a4,a0                     ; Activation record (a0 = arec)
  511.         sub.l   #RESBASE,a0
  512.         move.l  userdata(a4),a1           ; User data pointer (a1 = udata)
  513.         move.l  8(sp),d0                  ; y1
  514.         move.l  12(sp),d1                 ; y2
  515. fp1:    rts                               ; Call it (d0 = y1, d1 = y2)
  516.  
  517. ;***************************************************************************
  518. ;
  519. ; Copy the page to the output.  Call the copy function if we have one.
  520. ;
  521. ;     void copypage(int num)
  522. ;
  523. ;***************************************************************************
  524.  
  525. copypage:
  526.         move.l  copyfunc(a4),d0           ; Get the function
  527.         beq.s   cp1
  528.         move.l  d0,-(sp)                  ; Push function
  529.         move.l  a4,a0                     ; Activation record (a0 = arec)
  530.         sub.l   #RESBASE,a0
  531.         move.l  userdata(a4),a1           ; User data pointer (a1 = udata)
  532.         move.l  8(sp),d0                  ; num
  533. cp1:    rts                               ; Call it (d0 = num)
  534.  
  535. ;***************************************************************************
  536. ;
  537. ;    The Data segment (data + bss)
  538. ;
  539. ;***************************************************************************
  540.  
  541.         csect   __MERGED,1         ; Data
  542.  
  543.         xref    attnflags          ; Required machine flags (68881/68020...)
  544.  
  545.         csect   __MERGED,2         ; BSS
  546.  
  547.         xref    DOSBase            ; DOS library base
  548.  
  549.         xref    userdata           ; User data pointer
  550.         xref    flushfunc          ; Flush page function
  551.         xref    copyfunc           ; Copy page function
  552.  
  553.         xdef    SysBase
  554.         xdef    curdir
  555.         xdef    _oserr
  556.         xdef    _OSERR
  557.         xdef    _FPERR
  558.         xdef    _ONBREAK
  559.  
  560.  
  561. SysBase:        ds.b    4          ; Exec library base
  562. curdir:         ds.b    4          ; Current directory
  563. _oserr          equ     *
  564. _OSERR:         ds.b    4          ; Operating system error number
  565. _FPERR:           ds.b    4          ; Floating point error number
  566. _ONBREAK:       ds.b    4          ; Break trap routine
  567.  
  568.         end
  569.  
  570. ; End of file "postlib.a"
  571.